package com.wzx.user.sdk.controller;

import com.aliyun.tea.*;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsRequest;
import com.aliyuncs.dysmsapi.model.v20170525.SendSmsResponse;
import com.aliyuncs.exceptions.ClientException;
import com.aliyuncs.profile.DefaultProfile;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author wzx
 * @version 1.0
 * @date 2023/3/15 - 22:16
 * @description 标题
 */
//@RestController
//@RequestMapping("/sms")
public class SmsController {

    @Value("${demoservice.sms.validateCodeTemplateCode}")
    private String CODE;

    @Value("${demoservice.sms.signName}")
    private String SIGN_NAME;

    @Value("${demoservice.sms.parameterName}")
    private String PARAMETER_NAME;

    @Value("${demoservice.sms.accessKeyId}")
    private String ACCESS_KEY_ID;

    @Value("${demoservice.sms.accessKeySecret}")
    private String ACCESS_KEY_SECRET;

    /*@GetMapping("/tezts")
    public void test() {
        //测试手机验证码
        sendMessage("18873663360");
    }*/


    /**
     * 发送短信
     *
     * @param signName     签名
     * @param templateCode 模板
     * @param phoneNumbers 手机号
     * @param param        参数
     */
    public void sendMessage(String phoneNumbers) {
        DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou",
                ACCESS_KEY_ID,
                ACCESS_KEY_SECRET);
        IAcsClient client = new DefaultAcsClient(profile);

        SendSmsRequest request = new SendSmsRequest();
        request.setSysRegionId("cn-hangzhou");
        request.setPhoneNumbers(phoneNumbers);
        request.setSignName(SIGN_NAME);
        request.setTemplateCode(CODE);
        request.setTemplateParam("{\"code\":\"" + 6666 + "\"}");
        try {
            SendSmsResponse response = client.getAcsResponse(request);
            System.err.println("response.getMessage() = " + response.getMessage());
            System.err.println("response.getCode() = " + response.getCode());
            System.out.println("response.getRequestId() = " + response.getRequestId());

            System.err.println("response = " + response);
            //System.err.println("短信发送成功");
        } catch (ClientException e) {
            e.printStackTrace();
        }
    }




}
